package com.flynn.rock.crm.repository.employee;

import com.flynn.rock.crm.entity.employee.EmployeeEntity;
import com.flynn.rock.crm.model.employee.EmployeeCriteria;
import com.flynn.rock.enums.customer.ReceiveStatus;
import com.flynn.rock.util.JpaQueryHelper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Long>, JpaSpecificationExecutor<EmployeeEntity> {

    EmployeeEntity findByUserId(Long userId);

    List<EmployeeEntity> findAllByDeptIdInAndReceiveStatus(List<Long> deptId, ReceiveStatus receiveStatus);

    default Page<EmployeeEntity> pageEmployee(EmployeeCriteria criteria, Pageable pageable) {
        return this.findAll(
                ((root, query, criteriaBuilder) -> JpaQueryHelper.getPredicate(root, criteria, criteriaBuilder)),
                pageable
        );
    }
}
